#include <DHT11.h>
#include <Timer.h>
#include <Button.h>
#include <SerialData.h>

DHT11 dht11 = DHT11(2);	//Pin
Timer sensorTemp = Timer(2000, readTempHum);	//Milisegundos, Metodo

Button button1 = Button(7, 3);	//PinButton, SwitchButton
Button button2 = Button(8, 4);
Button button3 = Button(9, 5);
Button button4 = Button(10, 6);

SerialData serialData = SerialData();


void setup() 
{
  Serial.begin(9600);
  
  pinMode(7, INPUT);      
  pinMode(8, INPUT);     
  pinMode(9, INPUT);      
  pinMode(10, INPUT);     
  pinMode(1, OUTPUT);      
  pinMode(2, OUTPUT);     
  pinMode(3, OUTPUT);      
  pinMode(4, OUTPUT);     
}


void loop()
{   
  if (serialData.check("S1")) button1.push();
  if (serialData.check("S2")) button2.push();
  if (serialData.check("S3")) button3.push();
  if (serialData.check("S4")) button4.push();
  
  button1.check();
  button2.check();
  button3.check();
  button4.check();
  
  sensorTemp.check();
}


void readTempHum()
{
  dht11.read();
  
  //Envia lectura de temperatura y humedad
  serialData.write("<T" + (String)dht11.temperature + "@" + "H" + (String)dht11.humidity + "@>");
}
